﻿// <copyright file="Groups.xaml.cs" company="company"> 
// (C) 2010 . All rights reserved
// </copyright>
// <author>Lukasz Bartczak</author>

namespace SecretaryAppNav.Views
{
    using System;
    using System.Windows.Controls;
    using SecretaryAppNav.ClientWcfService;
    using Telerik.Windows.Controls;

    /// <summary>
    /// Codebehind class Groups
    /// </summary>
    public partial class Groups : Page
    {
        /// <summary>
        /// Service proxy
        /// </summary>
        private Service1Client client = new Service1Client();

        /// <summary>
        /// Initializes a new instance of the <see cref="Groups"/> class.
        /// </summary>
        public Groups()
        {
            InitializeComponent();
            this.client.GetGroupsCompleted += new EventHandler<GetGroupsCompletedEventArgs>(this.Client_GetGroupsCompleted);
            this.client.GetChildAndOpiekunByGroupCompleted += new EventHandler<GetChildAndOpiekunByGroupCompletedEventArgs>(this.Client_GetChildAndOpiekunByGroupCompleted);
            this.client.GetGroupsAsync();
        }

        /// <summary>
        /// Handles the GetChildAndOpiekunByGroupCompleted event of the Client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SecretaryAppNav.ClientWcfService.GetChildAndOpiekunByGroupCompletedEventArgs"/> instance containing the event data.</param>
        private void Client_GetChildAndOpiekunByGroupCompleted(object sender, GetChildAndOpiekunByGroupCompletedEventArgs e)
        {
            this.radGridView1.ItemsSource = e.Result;
        }

        /// <summary>
        /// Handles the GetGroupsCompleted event of the Client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SecretaryAppNav.ClientWcfService.GetGroupsCompletedEventArgs"/> instance containing the event data.</param>
        private void Client_GetGroupsCompleted(object sender, GetGroupsCompletedEventArgs e)
        {
            this.groups.DataContext = e.Result;
        }

        /// <summary>
        /// Handles the SelectionChanged event of the Groups control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void Groups_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            RadComboBox cb = (RadComboBox)sender;
            this.client.GetChildAndOpiekunByGroupAsync((int)cb.SelectedValue);
        }
    }
}
